package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.CostBillAddDTO;
import org.jsola.hr.dto.CostBillUpdateDTO;
import org.jsola.hr.entity.CostBillDO;
import org.jsola.hr.query.CostBillQuery;
import org.jsola.hr.service.ICostBillService;
import org.jsola.hr.vo.CostBillVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 费用账单
 *
 * @author zhr
 */
@Component
public class CostBillTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICostBillService costBillService;

    /**
     * 生成add测试数据
     * @return CostBillAddDTO
     */
    public CostBillAddDTO getCostBillAddDTO(){
        CostBillAddDTO costBillAddDTO = new CostBillAddDTO();
        costBillAddDTO.setAnnexUrl(getRandomValue("text",2147483647));
        costBillAddDTO.setAutoSystem(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        costBillAddDTO.setNumber(SafeKit.getInteger(getRandomValue("int",11)));
        costBillAddDTO.setYear(SafeKit.getInteger(getRandomValue("int",4)));
        costBillAddDTO.setMonth(SafeKit.getInteger(getRandomValue("int",2)));
        costBillAddDTO.setSubjectType(getRandomValue("varchar",50));
        costBillAddDTO.setSubjectId(getRandomValue("text",2147483647));
        costBillAddDTO.setBillName(getRandomValue("varchar",50));
        costBillAddDTO.setCompanyId(getRandomValue("text",2147483647));
        costBillAddDTO.setCompanyName(getRandomValue("varchar",100));
        costBillAddDTO.setPersonalSocAmount(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        costBillAddDTO.setPersonalPfAmount(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        costBillAddDTO.setCompanySocAmount(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        costBillAddDTO.setCompanyPfAmount(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        costBillAddDTO.setFine(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        costBillAddDTO.setCalculateSalaryNumber(SafeKit.getInteger(getRandomValue("int",11)));
        costBillAddDTO.setPayrollName(getRandomValue("varchar",50));
        costBillAddDTO.setTotalTax(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        costBillAddDTO.setTotalAmount(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        costBillAddDTO.setFinalAmount(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        costBillAddDTO.setIsConfirm(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        costBillAddDTO.setUserApproId(getRandomValue("varchar",50));
        costBillAddDTO.setIsMerge(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        return costBillAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CostBillUpdateDTO
     */
    public CostBillUpdateDTO getCostBillUpdateDTO(CostBillVO costBillVO) {
        return costBillService.selectDOById(costBillVO.getId(), SITE_ID).to(CostBillUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CostBillQuery
     */
    public CostBillQuery getCostBillQuery() {
        CostBillQuery costBillQuery = new CostBillQuery();
        List<CostBillDO> costBillDOList = costBillService.list(new CostBillDO(), SITE_ID);
        if (!CollectionUtils.isEmpty(costBillDOList)) {
            CostBillDO costBillDO = costBillDOList.get(0);
            costBillQuery = costBillDO.to(CostBillQuery.class);
        }
        return costBillQuery;
    }

    /**
     * 保存示例
     *
     * @return CostBillVO
     */
    public CostBillVO saveCostBillExample() {
        CostBillAddDTO addDTO = this.getCostBillAddDTO();
        CostBillVO costBillVO = costBillService.save(addDTO, buildTokenUser());
        return costBillVO;
    }


}

